package org.alis.rpc.route.impl;

import com.google.common.hash.Hashing;
import org.alis.rpc.common.protocol.RpcProtocol;
import org.alis.rpc.route.AbstractRpcLoadBalance;

import java.util.List;

/**
 * RpcLoadBalanceConsistentHash desc:  一致性hash算法负载
 *
 * @author luochuan
 * @date 2020/10/9 13:50
 */
public class RpcLoadBalanceConsistentHash<V> extends AbstractRpcLoadBalance<V> {

    @Override
    public RpcProtocol doRoute(String serviceKey, List<RpcProtocol> addressList) {
        return addressList.get(Hashing.consistentHash(serviceKey.hashCode(), addressList.size()));
    }


}
